home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDTrackTime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.3 KB  |  116 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDTrackTime - An XFCN to report time of a track
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDTrackTime.c
  11.     link -sn Main=CDTrackTime -sn STDIO=CDTrackTime ∂
  12.          -sn INTENV=CDTrackTime -rt XFCN=42 ∂
  13.          -m CDTrackTime CDTrackTime.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27.  
  28. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  29.  
  30.  
  31. /************************************************************************
  32.  *
  33.  *  Function:        CDTrackTime
  34.  *
  35.  *  Purpose:        return the length of a track.
  36.  *
  37.  *  Returns:        either 0, or an error
  38.  *                    if it's a negative number, it's an error
  39.  *
  40.  *  Side Effects:
  41.  *
  42.  *  Description:    We need no parameter:
  43.  *                    Get the ioRefNum that we got from previously calling
  44.  *                    CDOpen() by accessing the famous global
  45.  *                    call the driver with a READQ call to find out
  46.  *                    how absolute minute, second, block remaining.
  47.  *
  48.  ************************************************************************/
  49. pascal void
  50. CDTrackTime(paramPtr)
  51. XCmdBlockPtr    paramPtr;
  52. {
  53.     Str31    returnString;
  54.     OSErr    result;
  55.     short    ioRefNum;
  56.     Handle    refHandle;
  57.     long    Remaining[3];    /* minute, second, block */
  58.     long    endMinute, endSecond, endBlock;
  59.     long    startMinute, startSecond, startBlock;
  60.     long    trackNo;
  61.     
  62.     /* Must be one parameter, or no parameters */
  63.     if ((paramPtr->paramCount) > 1)
  64.     {
  65.         /* Report error in parameters by returning -1 */
  66.         NumToStr(paramPtr, (long) -1, &returnString);
  67.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  68.         return;
  69.     }
  70.     
  71.     /* Get the global ioRefNum and convert it. */
  72.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  73.     ioRefNum = atoi(*(refHandle));
  74.     DisposHandle(refHandle);
  75.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  76.     
  77.     
  78. /* If we were passed a track number, use it instead of the current track */
  79.     if ((paramPtr->paramCount) == 1)
  80.         trackNo = atoi((char *)*(paramPtr->params[0]));
  81.     else
  82.         result = ReadQ(ioRefNum, &trackNo, &startMinute, &startSecond, &startBlock);
  83.             
  84.     result = TrackStart(ioRefNum, trackNo, &startMinute, &startSecond, &startBlock);
  85.     
  86.     if (result == noErr)
  87.         result = TrackStart(ioRefNum, trackNo+1, &endMinute, &endSecond, &endBlock);
  88.     
  89.     if (result != noErr)    /* we specified an invalid track. Use disc time */
  90.         result = DiscTime(ioRefNum, &endMinute, &endSecond, &endBlock);
  91.         
  92.     if (result == noErr)
  93.     {
  94.         TimeDiff(&Remaining[0], &Remaining[1], &Remaining[2],
  95.                  endMinute, endSecond, endBlock,
  96.                  startMinute, startSecond, startBlock);
  97.     }
  98.  
  99.     if (result == noErr)
  100.     {
  101.         /* convert each value to a string, concatenate, & return. */
  102.         FormatString(&returnString, Remaining, 3);
  103.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  104.     }
  105.     else
  106.     {
  107.         /* We got an error. Convert result to string & return it as error */
  108.         NumToStr(paramPtr, (long) result, &returnString);
  109.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  110.     }
  111. }
  112.  
  113.  
  114. /* C routines for HyperCard callbacks */
  115. #include <XCmdGlue.inc.c>
  116.